package jzOffer;

import java.util.ArrayList;
import java.util.Stack;

/**
 * @author 郝文雪
 * @date 2022/7/18 16:27
 * @Description 从尾到头打印链表
 */
public class JZ6 {
    public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
        Stack<Integer> stack=new Stack<>();
        while(listNode!=null){
            stack.push(listNode.val);
            listNode=listNode.next;
        }
        ArrayList<Integer> list=new ArrayList<>();
        while(!stack.isEmpty()){
            list.add(stack.pop());
        }
        return list;
    }
}
